//
//  UIViewController+LLT_LoginAndRegist_LXM.m
//  CoderLLT
//
//  Created by 刘晓萌 on 15/12/23.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "UIViewController+LLT_LoginAndRegist_LXM.h"
#import <CommonCrypto/CommonCrypto.h>
#import <AVOSCloud/AVOSCloud.h>
@implementation UIViewController (LLT_LoginAndRegist_LXM)

#pragma mark --- 设置背景图滚动方法

-(void)changBackImageAction:(UIScrollView *)scrollView andFlag:(BOOL)flag{
   
}

#pragma mark --- Alert提示方法

/**
 * 添加简单allert提示
 */
-(void)showAlert:(NSString *)alertTitle andAlertString:(NSString *)alertContent{
    [self showAlert:alertTitle andAlertString:alertContent andHandler:nil];
}

/**
 * 添加复杂点儿allert提示
 */
-(void)showAlert:(NSString *)alertTitle andAlertString:(NSString *)alertContent andHandler:(void (^ __nullable)(UIAlertAction *action))handler{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:alertTitle message:alertContent preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:handler]];
    [self presentViewController:alertVC animated:YES completion:nil];
}

#pragma mark --- 判断是否符合电话号码规范

/**
 *  判断是否符合电话号码规范
 *
 *  @param phoneNum 电话号码
 *
 *  @return 布尔值
 */
-(BOOL)authenticatePhoneNum:(NSString *)phoneNum{
    NSString *regex = @"^1[3|4|5|7|8][0-9]\\d{8}$";
    NSPredicate *predicateRe1 = [NSPredicate predicateWithFormat:@"self matches %@", regex];
    BOOL resualt = [predicateRe1 evaluateWithObject:phoneNum];
    return resualt;
}

#pragma mark --- 密码MD5加密

-(NSString *)md5StrWithString:(NSString *)string
{
    char result[16];
    CC_MD5(string.UTF8String,(CC_LONG)strlen(string.UTF8String),(unsigned char *)result);
    NSMutableString *md5Str = [NSMutableString new];
    for (int i = 0; i < 16; i ++)
    {
        [md5Str appendFormat:@"%02X",result[i]];
    }
    return md5Str;
}

#pragma mark --- 动画方法
#pragma CATransition动画实现
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view
{
    //创建CATransition对象
    CATransition *animation = [CATransition animation];
    //设置运动时间
    animation.duration = 1;//DURATION;
    //设置运动type
    animation.type = type;
    if (subtype != nil) {
        //设置子类
        animation.subtype = subtype;
    }
    //设置运动速度
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    [view.layer addAnimation:animation forKey:@"animation"];
}

#pragma mark --- 判断是否登陆/或是以游客登陆
/**
 * 判断是否登陆/或是以游客登陆
 */
-(BOOL)isonLine{
    AVUser *currentUser = [AVUser currentUser];
    if (currentUser != nil && currentUser.mobilePhoneVerified) {
        return YES;
    } else {
        return NO;
    }
}

@end
